package com.chuangsi.project.admin.controller.admin;


import com.chuangsi.framework.web.controller.BaseController;
import com.chuangsi.framework.web.domain.ResultObject;
import com.chuangsi.project.admin.dto.admin.approve.ReqAppoveConfigUpdateDto;
import com.chuangsi.project.admin.dto.admin.approve.ReqApproveConfigDetailDto;
import com.chuangsi.project.admin.dto.admin.approve.ResApproveConfigDetailDto;
import com.chuangsi.project.admin.dto.admin.approve.ResApproveConfigListDto;
import com.chuangsi.project.admin.service.ApproveConfigService;
import com.chuangsi.project.admin.service.ApproveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author wangshengming
 * @date 2023/3/27
 */
@Api(tags = "审批流程管理")
@RestController
@RequestMapping("/adminApi/approve")
public class ApproveController  extends BaseController {

    @Autowired
    private ApproveService approveService;
    @Autowired
    private ApproveConfigService approveConfigService;

    @ApiOperation(value = "审批流程管理",notes = "王圣铭")
    @PostMapping("/configList")
    public ResultObject<List<ResApproveConfigListDto>> configList(){
        List<ResApproveConfigListDto> list = approveConfigService.configList();
        return ResultObject.ok("查询成功").setData(list);
    }

    @ApiOperation(value = "审批流程详情",notes = "王圣铭")
    @PostMapping("/configDetail")
    public ResultObject<List<ResApproveConfigDetailDto>> configDetail(@RequestBody @Valid ReqApproveConfigDetailDto req){
        List<ResApproveConfigDetailDto> res = approveConfigService.configDetail(req);
        return ResultObject.ok("查询成功").setData(res);
    }

    @ApiOperation(value = "审批流程编辑",notes = "王圣铭")
    @PostMapping("/updateConfig")
    public ResultObject<Void> updateConfig(@RequestBody @Valid ReqAppoveConfigUpdateDto req){
        boolean flag = approveConfigService.updateConfig(req);
        if(flag){return ResultObject.ok("操作成功");}
        else {return ResultObject.error("操作失败");}
    }





}
